package com.tencreat.service.pay.impl;

import com.github.wxpay.sdk.WXPayConfig;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.FileInputStream;
import java.io.InputStream;

public class WxPayConfigImpl implements WXPayConfig {
    public static String url = "回调接口";
    private static WxPayConfigImpl wxPayConfig;
    private byte[] certData = null;

    public static WxPayConfigImpl getInstance() {
        if (wxPayConfig == null) {
            synchronized (WxPayConfigImpl.class) {
                wxPayConfig = new WxPayConfigImpl();
            }
        }
        return wxPayConfig;
    }

    public WxPayConfigImpl() {
        try {
            InputStream is = new FileInputStream("C:\\Windows\\System32\\cert\\apiclient_cert.p12");
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            byte[] bs = new byte[1024];
            int cnt = -1;
            while ((cnt = is.read(bs)) != -1) {
                baos.write(bs, 0, cnt);
            }
            is.close();
            certData = baos.toByteArray();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    public String getAppID() {
        return "你自己的AppId";
    }

    @Override
    public String getMchID() {
        return "你自己的设备码";
    }

    @Override
    public String getKey() {
        return "你自己的key";
    }

    @Override
    public InputStream getCertStream() {
        ByteArrayInputStream certBis;
        certBis = new ByteArrayInputStream(this.certData);
        return certBis;
    }

    @Override
    public int getHttpConnectTimeoutMs() {
        return 8000;
    }

    @Override
    public int getHttpReadTimeoutMs() {
        return 10000;
    }


    public String getPrimaryDomain() {
        return "api.mch.weixin.qq.com";
    }

    public String getNotifyUrl(){
        return url;
    }

}
